home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / interp / value.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.5 KB  |  98 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: value.c,v 1.3 94/10/05 21:04:51 nkramer Exp $
  27. *
  28. * This file implements value cells.
  29. *
  30. \**********************************************************************/
  31.  
  32. #include "../compat/std-c.h"
  33.  
  34. #include "mindy.h"
  35. #include "gc.h"
  36. #include "obj.h"
  37. #include "class.h"
  38. #include "value.h"
  39.  
  40. struct value_cell {
  41.     obj_t class;
  42.     obj_t value;
  43. };
  44.  
  45. static obj_t obj_ValueCellClass = NULL;
  46.  
  47. obj_t make_value_cell(obj_t value)
  48. {
  49.     obj_t res = alloc(obj_ValueCellClass, sizeof(struct value_cell));
  50.  
  51.     obj_ptr(struct value_cell *, res)->value = value;
  52.  
  53.     return res;
  54. }
  55.  
  56. obj_t value_cell_ref(obj_t value_cell)
  57. {
  58.     return obj_ptr(struct value_cell *, value_cell)->value;
  59. }
  60.  
  61. obj_t value_cell_set(obj_t value_cell, obj_t value)
  62. {
  63.     return obj_ptr(struct value_cell *, value_cell)->value = value;
  64. }
  65.  
  66.  
  67. /* GC Routines */
  68.  
  69. static int scav_value_cell(struct object *ptr)
  70. {
  71.     scavenge(&((struct value_cell *)ptr)->value);
  72.     return sizeof(struct value_cell);
  73. }
  74.  
  75. static obj_t trans_value_cell(obj_t value_cell)
  76. {
  77.     return transport(value_cell, sizeof(struct value_cell));
  78. }
  79.  
  80. void scavenge_value_roots(void)
  81. {
  82.     scavenge(&obj_ValueCellClass);
  83. }
  84.  
  85.  
  86. /* Init stuff */
  87.  
  88. void make_value_classes(void)
  89. {
  90.     obj_ValueCellClass = make_builtin_class(scav_value_cell, trans_value_cell);
  91. }
  92.  
  93. void init_value_classes(void)
  94. {
  95.     init_builtin_class(obj_ValueCellClass, "<value-cell>",
  96.                obj_ObjectClass, NULL);
  97. }
  98.